﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;

namespace Total_Mayhem.Common
{
    public static class Threadding
    {
        public static System.Threading.AutoResetEvent WaitForever = new AutoResetEvent(false);

        public static void QueueBackroundTask(Action Task){
            System.Threading.ThreadPool.QueueUserWorkItem(state => Task());
        }

        public static void QueueBackroundTaskwithDelay(TimeSpan Delay, Action Task)
        {
            //Use WaitForever semaphore and RegisterWaitForSingleObject method to delate execution of task on background thread.
            System.Threading.ThreadPool.RegisterWaitForSingleObject(WaitForever, (state, bTimeout) => Task(), null, Delay, true);
        }
    }
}
